package com.example.thridhero.zbxquery;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import org.litepal.crud.DataSupport;
import org.litepal.tablemanager.Connector;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    public static final String TAG = "MainActivity";

    private Button createDBBtn;
    private Button readDataBtn;
    private Button initDbBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        createDBBtn = (Button) findViewById(R.id.create_db);
        readDataBtn = (Button) findViewById(R.id.read_db);
        initDbBtn = (Button) findViewById(R.id.init_db);

        createDBBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Connector.getDatabase();
            }
        });

        readDataBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyDatabaseHelper myDatabaseHelper = new MyDatabaseHelper(MainActivity.this,"test.db",null,10 );
                SQLiteDatabase sqlLiteDatabase =  myDatabaseHelper.getWritableDatabase();
                sqlLiteDatabase.execSQL("insert into insurance ( code, companyname, datetype, distypt, feetype, policy_name, productname, productstate, productway, salestate, stopsaledate, type, uuid) select code, companyname, datetype, distypt, feetype, policy_name, productname, productstate, productway, salestate, stopsaledate, type, uuid from iachina");

                Insurance insurance = DataSupport.findAll(Insurance.class,17);



            }
        });
        initDbBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InitData.initData();
            }
        });

    }

}
